package com.ruoyi.device.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.security.annotation.InnerAuth;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.device.api.domain.DeviceOnline;
import com.ruoyi.device.service.IDeviceOnlineService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 设备在线信息Controller
 * 
 * @author luogongquan
 * @date 2024-09-06
 */
@RestController
@RequestMapping("/deviceOnline")
public class DeviceOnlineController extends BaseController
{
    @Autowired
    private IDeviceOnlineService deviceOnlineService;

    /**
     * 查询设备在线信息列表
     */
    @RequiresPermissions("device:deviceOnline:list")
    @GetMapping("/list")
    public TableDataInfo list(DeviceOnline deviceOnline)
    {
        startPage();
        List<DeviceOnline> list = deviceOnlineService.selectDeviceOnlineList(deviceOnline);
        return getDataTable(list);
    }

    /**
     * 导出设备在线信息列表
     */
    @RequiresPermissions("device:deviceOnline:export")
    @Log(title = "设备在线信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DeviceOnline deviceOnline)
    {
        List<DeviceOnline> list = deviceOnlineService.selectDeviceOnlineList(deviceOnline);
        ExcelUtil<DeviceOnline> util = new ExcelUtil<DeviceOnline>(DeviceOnline.class);
        util.exportExcel(response, list, "设备在线信息数据");
    }

    /**
     * 获取设备在线信息详细信息
     */
    @RequiresPermissions("device:deviceOnline:query")
    @GetMapping(value = "/{deviceId}")
    public AjaxResult getInfo(@PathVariable("deviceId") Long deviceId)
    {
        return success(deviceOnlineService.selectDeviceOnlineByDeviceId(deviceId));
    }

    /**
     * 新增设备在线信息
     */
    @RequiresPermissions("device:deviceOnline:add")
    @Log(title = "设备在线信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DeviceOnline deviceOnline)
    {
        return toAjax(deviceOnlineService.insertDeviceOnline(deviceOnline));
    }

    /**
     * 修改设备在线信息
     */
    @RequiresPermissions("device:deviceOnline:edit")
    @Log(title = "设备在线信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DeviceOnline deviceOnline)
    {
        return toAjax(deviceOnlineService.updateDeviceOnline(deviceOnline));
    }

    /**
     * 删除设备在线信息
     */
    @RequiresPermissions("device:deviceOnline:remove")
    @Log(title = "设备在线信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{deviceIds}")
    public AjaxResult remove(@PathVariable Long[] deviceIds)
    {
        return toAjax(deviceOnlineService.deleteDeviceOnlineByDeviceIds(deviceIds));
    }
    /**
     * 新增设备在线信息
     */
    @InnerAuth
    @PutMapping("/updateDeviceStatus")
    public R<Boolean> updateDeviceStatus(@RequestBody DeviceOnline deviceOnline){

        return R.ok(deviceOnlineService.InsertOrUpdateDeviceOnline(deviceOnline));
    }
}
